package com.ujiuye.demo;

import com.ujiuye.bean.MyJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class DemoQuartz {
    public static void main(String[] args) throws SchedulerException, InterruptedException {
        //1.job
        JobDetail job = JobBuilder.newJob(MyJob.class).withIdentity("job1", "group1").build();

        //2.时间规则表     10秒 10次
        SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(10).withRepeatCount(10);

        //3.创建触发器(simpletriiger)
        SimpleTrigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1", "group1").withSchedule(simpleScheduleBuilder).startNow().build();

        //4.调度器
        Scheduler scheduler = new StdSchedulerFactory().getScheduler();
        scheduler.scheduleJob(job, trigger);
        scheduler.start();

        Thread.sleep(120*1000);

    }
}
